public class demo4 {
    int sum=0;
    boolean []chek;
    public int countArrangement(int n) {
        chek=new boolean[n+1];
        dfs(n,1);
        return sum;
    }
    public void dfs(int n,int pos){
        if(pos==n+1){//pos=n时还需要进行判断，当pos==n+1时出递归
            sum++;
            return;
        }
        for(int i=1;i<=n;i++){
            //只需要注意符合条件的
            if(!chek[i]&&(i%pos==0||pos%i==0)){
                chek[i]=true;
                dfs(n,pos+1);
                chek[i]=false;
            }
        }
    }
}
